from selenium import webdriver
from selenium.webdriver.common.by import By
import time
from selenium.webdriver import ChromeOptions
# 规避被检测的风险
option = ChromeOptions()
option.add_experimental_option('excludeSwitches', ['enable-automation'])
browser = webdriver.Chrome(options=option)
browser.get('https://www.taobao.com')
input_first = browser.find_element_by_id('q')
input_second = browser.find_element_by_css_selector('#q')
input_third = browser.find_element_by_xpath('//*[@id="q"]')
input_fourth = browser.find_element(By.ID,'q')
print(input_first,input_second,input_third,input_fourth)

lis = browser.find_elements_by_css_selector('.service-bd li')
lis1 = browser.find_elements(By.CSS_SELECTOR,'.service-bd li')
print(lis)
print(lis1)

#节点交互
input = browser.find_element_by_id('q')
input.send_keys('Iphone')#输入文字
time.sleep(3)
input.clear()#3秒后清空
input.send_keys('iPad')#输入文字
button = browser.find_element_by_class_name('btn-search')#获取搜索按钮
button.click()#点击搜索按钮
time.sleep(2)
# 动作链
# 此例完成一个节点的拖拽操作，将某个节点从一处拖拽到另一处
from selenium.webdriver import ActionChains
url='https://www.runoob.com/try/try.php?filename=jqueryui-api-droppable'
browser.get(url)
browser.switch_to.frame('iframeResult')
source = browser.find_element_by_css_selector('#draggable')
target = browser.find_element_by_css_selector('#droppable')
print(source)
print(target)
actions = ActionChains(browser)
actions.drag_and_drop(source,target)
actions.perform()
# browser.close()
'''
find_element_by_id
find_element_by_name
find_element_by_xpath
find_element_by_link_text
find_element_by_partial_link_text
find_element_by_tag_name
find_element_by_class_name
find_element_by_css_selector
+++++++++++++++++++++++++++++++++++++
find_elements_by_id
find_elements_by_name
find_elements_by_xpath
find_elements_by_link_text
find_elements_by_partial_link_text
find_elements_by_tag_name
find_elements_by_class_name
find_elements_by_css_selector
'''